# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : 生产者 Producer（发送消息）.py
# @Author: dongguangwen
# @Date  : 2025-04-12 12:09
import pika

# 连接到本地 RabbitMQ 服务
credentials = pika.PlainCredentials('admin', 'password')
connection = pika.BlockingConnection(
    pika.ConnectionParameters('192.168.1.119', credentials=credentials, virtual_host='my_vhost'))
channel = connection.channel()

# 声明队列（如果队列不存在就创建）
channel.queue_declare(queue='hello')

# 发送消息
channel.basic_publish(exchange='',
                      routing_key='hello',
                      body='Hello RabbitMQ!')
print("[x] 发送完成：'Hello RabbitMQ!'")

# 关闭连接
connection.close()